#!/bin/bash

set -e
cd $(dirname $(realpath $0))/../sqldb

CONT_NAME=seaorm-postgres
DB_PW=foobar
DB_URL="postgresql://postgres:$DB_PW@localhost/postgres"

set -x
pwd

trap "sudo docker stop $CONT_NAME" EXIT

# port 5432
sudo docker run \
       --rm -d \
       --name $CONT_NAME \
       --network host \
       -e POSTGRES_PASSWORD=$DB_PW \
       postgres

echo '==== APPLYING MIGRATIONS'
sea-orm-cli migrate refresh -v -u $DB_URL
echo '==== OK'

echo '==== GENERATING ENTITIES'
sea-orm-cli generate entity --lib -u $DB_URL -o ./src
echo '==== OK'
